<template>
  <div class="list-container" style="width:100%;">
    <div v-for="(item, index) in lists" class="article-list" :key="index" :style='{width: itemWidth}'>
      <div class="card-body">
        <img :src="item.image" alt="image" class="article-image" :style="{ width: imageTransWidth, height: imageTransHeight }">
        <div class="article-content" :style='{alignItems: alignItem}'>
         <div class="article-title" v-if="showTitle" :title="item.title" :style="titleStyle">{{ item.title }}</div>
         <div class="article-description"  v-if="showDescription" :title="item.description" :style="descriptionStyle">{{ item.description }}</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { isEmpty } from "lodash"
export default {
  name: 'CardList',
  props: {
    value: null,
    mode: {
      default: "edit", // 编辑模式和 edit， 展示模式 view
    },
    customCardLists: {
      type: Array,
      default: () => []
    },
    columnCount: {
      default: 4
    },
    mobileColumnCount: {
      default: 2
    },
    alignItem: {
       type: String,
       default: 'flex-start'
    },
    imageWidth: {
      type: String,
      default: '100%'
    },
    imageHeight: {
      type: String,
      default: '160px'
    },
    showTitle: {
       default: true
    },
    titleColor: {
      type: String,
      default: 'rgba(0, 0, 0)'
    },
    titleSize: {
      default: 14
    },
    titleWeight: {
      type: String,
      default: 'bolder'
    },
    showDescription: {
       default: true
    },
    descriptionColor: {
      type: String,
      default: 'rgba(0, 0, 0, 0.4)'
    },
    descriptionSize: {
      default: 14
    },
    descriptionWeight: {
      type: String,
      default: 'normal'
    }
  },
  data() {
    return {
      cardLists: [
        {
          image: "https://qcloudimg.tencent-cloud.cn/raw/478c35e469057b4d6352ccc14e00ebc5.png",
          title: "示例标题",
          description: "这是一段示例描述",
        },
         {
          image: "https://qcloudimg.tencent-cloud.cn/raw/478c35e469057b4d6352ccc14e00ebc5.png",
          title: "示例标题",
          description: "这是一段示例描述",
        },
        {
          image: "https://qcloudimg.tencent-cloud.cn/raw/478c35e469057b4d6352ccc14e00ebc5.png",
          title: "示例标题",
          description: "这是一段示例描述",
        },
         {
          image: "https://qcloudimg.tencent-cloud.cn/raw/478c35e469057b4d6352ccc14e00ebc5.png",
          title: "示例标题",
          description: "这是一段示例描述",
        },
      ]
    }
  },
  computed: {
    isDesigner() {
      return this.$attrs._source === 'designer'
    },
    mixEditable() {
      return !(this.$attrs.readonly || this.$attrs.disabled) && this.mode === "edit"
    },
    lists() {
     return this.isDesigner ? this.cardLists : isEmpty(this.customCardLists) ? this.cardLists : this.customCardLists
    },
    itemWidth() {
      console.log("列数:", this.columnCount)
      return `${100 / this.columnCount}%`;
    },
    titleStyle() {
      return {fontSize: this.titleSize + 'px', color: this.titleColor, fontWeight: this.titleWeight }
    },
    descriptionStyle() {
      return {fontSize: this.descriptionSize + 'px', color: this.descriptionColor, fontWeight: this.descriptionWeight }
    },
    imageTransWidth() {
      return this.imageWidth && this.imageWidth.includes('%') ? this.imageWidth : this.imageWidth + 'px'
    },
     imageTransHeight() {
      return this.imageHeight && this.imageHeight.includes('%') ? this.imageHeight : this.imageHeight + 'px'
    }
  },
};
</script>

<style scoped>
.list-container {
  display: flex;
  flex-wrap: wrap;
}
.article-list {
  padding: 0 8.14167px;
  box-sizing: border-box;
  cursor: auto;
  flex-grow: 1;
}
 .card-body {
  width: 100%;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.article-image {
  width: 100%;
  height: auto;
  object-fit: cover;
}

.article-content {
  width: 100%;
  display: flex;
  flex-direction: column;
  padding-top: 10px;
}

.article-title {
    display: -webkit-box;
    -webkit-line-clamp: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    color: rgb(0, 0, 0);
    font-weight: bolder;
    font-size: 14px;
    text-align: justify;
}

.article-description {
    display: -webkit-box;
    -webkit-line-clamp: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    color: rgba(0, 0, 0, 0.4);
    font-weight: normal;
    font-size: 14px;
    text-align: justify;
    padding-top: 10px;
}
</style>
